package com.ruoyi.web.controller.cabinet;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cabinet.domain.CabGoodsIn;
import com.ruoyi.cabinet.service.ICabGoodsInService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物品入库Controller
 *
 * @author ruoyi
 * @date 2024-01-30
 */
@RestController
@RequestMapping("/goods/goodsIn")
public class CabGoodsInController extends BaseController
{
    @Autowired
    private ICabGoodsInService cabGoodsInService;

    /**
     * 查询物品入库列表
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsIn:list')")
    @GetMapping("/list")
    public TableDataInfo list(CabGoodsIn cabGoodsIn)
    {
        startPage();
        List<CabGoodsIn> list = cabGoodsInService.selectCabGoodsInList(cabGoodsIn);
        return getDataTable(list);
    }

    /**
     * 导出物品入库列表
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsIn:export')")
    @Log(title = "物品入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CabGoodsIn cabGoodsIn)
    {
        List<CabGoodsIn> list = cabGoodsInService.selectCabGoodsInList(cabGoodsIn);
        ExcelUtil<CabGoodsIn> util = new ExcelUtil<CabGoodsIn>(CabGoodsIn.class);
        util.exportExcel(response, list, "物品入库数据");
    }

    /**
     * 获取物品入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsIn:query')")
    @GetMapping(value = "/{inId}")
    public AjaxResult getInfo(@PathVariable("inId") Long inId)
    {
        return success(cabGoodsInService.selectCabGoodsInByInId(inId));
    }

    /**
     * 新增物品入库
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsIn:add')")
    @Log(title = "物品入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CabGoodsIn cabGoodsIn)
    {
        return toAjax(cabGoodsInService.insertCabGoodsIn(cabGoodsIn));
    }

    /**
     * 修改物品入库
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsIn:edit')")
    @Log(title = "物品入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CabGoodsIn cabGoodsIn)
    {
        return toAjax(cabGoodsInService.updateCabGoodsIn(cabGoodsIn));
    }

    /**
     * 删除物品入库
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsIn:remove')")
    @Log(title = "物品入库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{inIds}")
    public AjaxResult remove(@PathVariable Long[] inIds)
    {
        return toAjax(cabGoodsInService.deleteCabGoodsInByInIds(inIds));
    }
}
